Completed
Pull Request — develop (#209)
by Xaver
28s
created

node.js ➔ ... ➔ showAutoupdate   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
dl 0
loc 3
rs 10
nop 2
1
define(['helper', 'moment'], function (helper, moment) {
2
  'use strict';
3
4
  var self = {};
5
6
  function showBar(V, v, width, warning) {
7
    return V.h('span',
8
      { props: { className: 'bar' + (warning ? ' warning' : '') } },
9
      [
10
        V.h('span',
11
          {
12
            style: { width: (width * 100) + '%' }
13
          }),
14
        V.h('label', v)
15
      ]
16
    );
17
  }
18
19
  self.showStatus = function showStatus(V, d) {
20
    return V.h('td',
21
      { props: { className: d.is_online ? 'online' : 'offline' } },
22
      _.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), {
23
        time: d.lastseen.fromNow(),
24
        date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
25
      }));
26
  };
27
28
  self.showGeoURI = function showGeoURI(V, d) {
29
    if (!helper.hasLocation(d)) {
30
      return undefined;
31
    }
32
33
    return V.h('td',
34
      V.h('a',
35
        { props: { href: 'geo:' + d.location.latitude + ',' + d.location.longitude } },
36
        Number(d.location.latitude.toFixed(6)) + ', ' + Number(d.location.longitude.toFixed(6))
37
      )
38
    );
39
  };
40
41
  self.showGateway = function showGateway(V, d) {
42
    return d.is_gateway ? _.t('yes') : undefined;
43
  };
44
45
  self.showFirmware = function showFirmware(V, d) {
46
    return [
47
      helper.dictGet(d, ['firmware', 'release']),
48
      helper.dictGet(d, ['firmware', 'base'])
49
    ].filter(function (n) {
50
      return n !== null;
51
    }).join(' / ') || undefined;
52
  };
53
54
  self.showUptime = function showUptime(V, d) {
55
    return moment.utc(d.uptime).local().fromNow(true);
56
  };
57
58
  self.showFirstSeen = function showFirstSeen(V, d) {
59
    return d.firstseen.fromNow(true);
60
  };
61
62
  self.showLoad = function showLoad(V, d) {
63
    if (!d.loadavg) {
64
      return undefined;
65
    }
66
    return showBar(V, d.loadavg.toFixed(2), d.loadavg % 1, d.loadavg >= d.nproc);
67
  };
68
69
  self.showRAM = function showRAM(V, d) {
70
    if (!d.memory_usage) {
71
      return undefined;
72
    }
73
    return showBar(V, Math.round(d.memory_usage * 100) + ' %', d.memory_usage, d.memory_usage >= 0.8);
74
  };
75
76
77
  self.showSite = function showSite(V, d, config) {
78
    var rt = d.site_code;
79
    if (config.siteNames) {
80
      config.siteNames.forEach(function (t) {
81
        if (d.site_code === t.site) {
82
          rt = t.name;
83
        }
84
      });
85
    }
86
    return rt;
87
  };
88
89
  self.showClients = function showClients(V, d) {
90
    if (!d.is_online) {
91
      return undefined;
92
    }
93
94
    var clients = [
95
      V.h('span', [
96
        d.clients > 0 ? d.clients : _.t('none'),
97
        V.h('br'),
98
        V.h('i', { props: { className: 'ion-people', title: _.t('node.clients') } })
99
      ]),
100
      V.h('span',
101
        { props: { className: 'legend-24ghz' } },
102
        [
103
          d.clients_wifi24,
104
          V.h('br'),
105
          V.h('span', { props: { className: 'symbol', title: '2,4 Ghz' } })
106
        ]),
107
      V.h('span',
108
        { props: { className: 'legend-5ghz' } },
109
        [
110
          d.clients_wifi5,
111
          V.h('br'),
112
          V.h('span', { props: { className: 'symbol', title: '5 Ghz' } })
113
        ]),
114
      V.h('span',
115
        { props: { className: 'legend-others' } },
116
        [
117
          d.clients_other,
118
          V.h('br'),
119
          V.h('span', { props: { className: 'symbol', title: _.t('others') } })
120
        ])
121
    ];
122
123
    return V.h('td', { props: { className: 'clients' } }, clients);
124
  };
125
126
  self.showIPs = function showIPs(V, d) {
127
    var string = [];
128
    var ips = d.network.addresses;
129
    ips.sort();
130
    ips.forEach(function (ip, i) {
131
      if (i > 0) {
132
        string.push(V.h('br'));
133
      }
134
135
      if (ip.indexOf('fe80:') !== 0) {
136
        string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip));
137
      } else {
138
        string.push(ip);
139
      }
140
    });
141
    return V.h('td', string);
142
  };
143
144
  self.showAutoupdate = function showAutoupdate(V, d) {
145
    return d.autoupdater.enabled ? _.t('node.activated', { branch: d.autoupdater.branch }) : _.t('node.deactivated');
146
  };
147
148
  return self;
149
});
150